﻿using System.Collections.Generic;
using System.Linq;
using HeritageAcademy.Models.ViewModels;

namespace HeritageAcademy.Models.Filters
{
    public class LibraryFilter : FilteredCourseFilter
    {
        #region Parameters 
        
        private readonly List<CourseFilter> _subFilters;
        
        #endregion 

        #region Ctor 
        
        public LibraryFilter(LibraryViewModel library) : base(library)
        {
            _subFilters = new List<CourseFilter>
                              {
                                  new AllCoursesFilter(library),
                                  new AuthorsFilter(library),
                                  new CourseTitlesFilter(library),
                                  new GenresCourseFilter(library),                                 
                                  new DecadeFilter(library),
                                  new RecentsFilter(library)
                              };
        }
        
        #endregion

        #region Properties 
        
        public override string DisplayText
        {
            get { return "Курс"; }
        }

        public override bool HasSubFilters
        {
            get { return true; }
        }

        public override List<CourseFilter> SubFilters
        {
            get { return _subFilters; }
        }
        
        #endregion Properties 

        #region Public Methods 
        
        public override void RefreshResults()
        {
            if (Library != null && Library.Courses != null)
            {
                Results = new List<CourseViewModel>(Library.Courses.AsEnumerable());
            }
        }

        public override void RefreshSubFilters()
        {
            // we never refresh
        }
        
        #endregion Public Methods 
    }
}